package com.loiot.baqi.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.loiot.baqi.controller.response.Pager;
import com.loiot.baqi.dao.TaskScheduleHeartbeatDao;
import com.loiot.baqi.service.TaskScheduleHeartbeatService;
import com.loiot.baqi.pojo.TaskScheduleHeartbeat;
import com.loiot.baqi.pojo.ZpJlJobLevels;


/**
 * 定时心跳 逻辑类。
 * 
 * @author  wangzx 
 * @creation 2016-05-13
 */
@Service("taskScheduleHeartbeatService")
@Transactional
public class TaskScheduleHeartbeatService{
    
    private Logger log = LoggerFactory.getLogger(this.getClass());
    
    @Resource
	private TaskScheduleHeartbeatDao taskScheduleHeartbeatDao;
	
	
	 /**
     * 查询 定时心跳列表分页
     * 
     * @param name 定时心跳名称
     * @param pageIndex 页索引
     * @return
     */
    public Pager<TaskScheduleHeartbeat> queryTaskScheduleHeartbeatListPage(HashMap<String,Object> pMap, int pageIndex)throws Exception {

        // 查询定时心跳列表总条数
        int totalResults = taskScheduleHeartbeatDao.getTaskScheduleHeartbeatListCount(pMap);

        // 构造一个分页器
        Pager<TaskScheduleHeartbeat> pager = new Pager<TaskScheduleHeartbeat>(totalResults, pageIndex);

        // 查询定时心跳列表
        List<TaskScheduleHeartbeat> taskScheduleHeartbeatList = taskScheduleHeartbeatDao.queryTaskScheduleHeartbeatList(pMap, pager.getSkipResults(),
                pager.getMaxResults());
        pager.setData(taskScheduleHeartbeatList);
        return pager;
    }
    
    
    
    
    /**
     * 查询 定时心跳（假）分页
     * 
     * @param name 定时心跳名称
     * @param pageIndex 页索引
     * @return
     */
    public Pager<TaskScheduleHeartbeat> queryFlasePageList(HashMap<String,Object> pMap, int pageIndex)throws Exception {
    	//假分页
    	Pager<TaskScheduleHeartbeat> pager = this.setPkList(pMap,pageIndex);
    	List<TaskScheduleHeartbeat> taskScheduleHeartbeatList = taskScheduleHeartbeatDao.queryTaskScheduleHeartbeatList(pMap);
        pager.setData(taskScheduleHeartbeatList);
        return pager;
    }
    
    /**
     * 设置 假分页id集合到Map中
     * @param pMap
     * @param pageIndex
     * @return
     * @throws Exception
     */
    public Pager<TaskScheduleHeartbeat> setPkList(HashMap<String,Object> pMap,int pageIndex) throws Exception{
    	  // 查询职位匹配信息列表总条数
        List<TaskScheduleHeartbeat> list = taskScheduleHeartbeatDao.queryTaskScheduleHeartbeatList(pMap);
        // 构造一个分页器
        Pager<TaskScheduleHeartbeat> pager = new Pager<TaskScheduleHeartbeat>(list.size(), pageIndex, 5,list);
        List<TaskScheduleHeartbeat> idsList = pager.getCurrentPageData();
        List<Long> ids =this.getIds(idsList);
        pMap.put("ids", ids);
        return pager;
    }
	
	 /**
     * 添加 定时心跳
     * 
     * @param p 参数对象
     */
    public TaskScheduleHeartbeat addTaskScheduleHeartbeat(TaskScheduleHeartbeat p)throws Exception {
       return  taskScheduleHeartbeatDao.addTaskScheduleHeartbeat(p);
    }
    
    /**
     * 修改 定时心跳
     * 
     * @param p 参数对象
     */
    public void updateTaskScheduleHeartbeat(TaskScheduleHeartbeat p)throws Exception {
        taskScheduleHeartbeatDao.updateTaskScheduleHeartbeat(p);
    }
    
    /**
     * 修改 定时心跳
     * 
     * @param p 参数对象
     */
    public void updateTaskScheduleHeartbeat(HashMap<String,Object> pMap)throws Exception {
        taskScheduleHeartbeatDao.updateTaskScheduleHeartbeat(pMap);
    }
    
    /**
     * 删除  定时心跳
     * 
     * @param id 主键
     */
    public void deleteTaskScheduleHeartbeat(java.lang.Long id)throws Exception {
        taskScheduleHeartbeatDao.deleteTaskScheduleHeartbeat(id);
    }
    
    /**
     * 删除  定时心跳
     * 
     * @param id 主键
     */
    public void deleteTaskScheduleHeartbeat(TaskScheduleHeartbeat p)throws Exception {
        taskScheduleHeartbeatDao.deleteTaskScheduleHeartbeat(p);
    }
    
    /**
     * 获得  定时心跳
     * 
     * @param id 定时心跳Id
     * 
     * @return 返回与ID匹配的定时心跳
     */
    public TaskScheduleHeartbeat getTaskScheduleHeartbeatById(java.lang.Long id)throws Exception {
        return  taskScheduleHeartbeatDao.getTaskScheduleHeartbeatById(id);
    }
    
    /**
     * 获得  定时心跳
     * 
     * @param id 定时心跳Id
     * 
     * @return 返回与ID匹配的定时心跳
     */
    public TaskScheduleHeartbeat getTaskScheduleHeartbeatById(java.lang.Long id,Long accountId)throws Exception {
        return  taskScheduleHeartbeatDao.getTaskScheduleHeartbeatById(id,accountId);
    }
    
    
    /**
     * 获得  定时心跳
     * 
     * @param id 定时心跳Id
     * 
     */
    public TaskScheduleHeartbeat getTaskScheduleHeartbeat(HashMap<String,Object> pMap)throws Exception {
    	return (TaskScheduleHeartbeat) taskScheduleHeartbeatDao.getTaskScheduleHeartbeat(pMap);
    }
    /**
     * 获得  定时心跳
     * 
     * @param name 定时心跳名称
     * 
     * @return 返回与NAME匹配的定时心跳
     */
    public TaskScheduleHeartbeat getTaskScheduleHeartbeatByName(String name)throws Exception {
        return  taskScheduleHeartbeatDao.getTaskScheduleHeartbeatByName(name);
    }
    
    /**
     * 查询 定时心跳列表
     * @return 定时心跳列表
     */
    public List<TaskScheduleHeartbeat> queryTaskScheduleHeartbeatList(HashMap<String,Object> pMap)throws Exception {
        return  taskScheduleHeartbeatDao.queryTaskScheduleHeartbeatList(pMap);
    }
    
    /**
     * 查询 定时心跳列表
     * @return 定时心跳列表
     */
    public List<TaskScheduleHeartbeat> queryTaskScheduleHeartbeatList(TaskScheduleHeartbeat p)throws Exception {
        return  taskScheduleHeartbeatDao.queryTaskScheduleHeartbeatList(p);
    }
    
    /**
     * 查询  定时心跳列表条数
     * 
     * @param name 定时心跳名称
     * @return 定时心跳列表条数
     */
    
    public int getTaskScheduleHeartbeatListCount(HashMap<String,Object> pMap)throws Exception {
        return  taskScheduleHeartbeatDao.getTaskScheduleHeartbeatListCount(pMap);
    }
    
    /**
     * 查询id集合
     * @return
     */
    public List<Long> getIds(List<TaskScheduleHeartbeat> list) {
    	List<Long> idsList = null;
        if(list!=null && list.size()>0) {
        	idsList = new ArrayList<Long>();
        	for (TaskScheduleHeartbeat b : list) {
            	idsList.add(null);
            }
        }
        return idsList;
    }
    
    /**
     * 统计 定时心跳列表
     * 
     * @return 定时心跳列表
     */
    public List<HashMap<String,Object>> statisticsTaskScheduleHeartbeatInfo(HashMap<String, Object> pMap )throws Exception {
    	return  taskScheduleHeartbeatDao.statisticsTaskScheduleHeartbeatInfo(pMap);
    }
}
